package com.maxatime.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.maxatime.common.constant.BusinessContents;
import com.maxatime.common.enums.BusinessEnum;
import com.maxatime.pojo.entity.ExamStudentBasicInfo;
import com.maxatime.service.Ssbkaoshi;
import com.maxatime.util.MyContent;

//9月份考试题
@Controller
@RequestMapping("/Ssbkaoshi")
public class Ssbconteroller {

	@Autowired
	Ssbkaoshi ssbkaoshi;

	@RequestMapping("/cha")
	public String quest() {
		return "Ssbkaoshi/kaoshi";
	}

	// 查询
	@RequestMapping("/quest")
	@ResponseBody
	public Map<String, Object> quest(@RequestBody ExamStudentBasicInfo examStudentBasicInfo) {
		Map<String, Object> m = new HashMap<>();
		List<ExamStudentBasicInfo> list = ssbkaoshi.listData(examStudentBasicInfo);
		m.put(MyContent.CODE, BusinessEnum.SUCCESS.getCode());
		m.put(MyContent.MSG, BusinessEnum.SUCCESS.getDesc());
		m.put(MyContent.DATA, list);
		return m;
	}

	// 新增
	@RequestMapping("/save")
	@ResponseBody
	public Map<String, Object> save(@RequestBody ExamStudentBasicInfo examStudentBasicInfo) {
		Map<String, Object> m = new HashMap<>();
		ssbkaoshi.insertSelective(examStudentBasicInfo);
		m.put(MyContent.CODE, BusinessEnum.SUCCESS.getCode());
		m.put(MyContent.MSG, BusinessEnum.SUCCESS.getDesc());
		return m;
	}
	//反显studentId
		@RequestMapping("/findstudentId")
		@ResponseBody
		public Map<String, Object> findstudentId(@RequestBody String jsonStr){
			JSONObject jsonObj = JSONObject.parseObject(jsonStr);
			String studentId = jsonObj.getString("studentId");
			System.out.println("studentId++" + studentId);
			ExamStudentBasicInfo examStudentBasicInfo = ssbkaoshi.findstudentId(studentId);
			Map<String, Object> m = new HashMap<>();
			m.put(MyContent.CODE, BusinessEnum.SUCCESS.getCode());
			m.put(MyContent.MSG, BusinessEnum.SUCCESS.getDesc());
			m.put(MyContent.DATA, examStudentBasicInfo);
			return m;
			
		}

	// 删除
	@RequestMapping("/del")
	@ResponseBody
	public Map<String, Object> del(@RequestBody String jsonStr) {
		JSONObject jsonObj = JSONObject.parseObject(jsonStr);
		String studentId = jsonObj.getString("studentId");
		ssbkaoshi.deleteByPrimaryKey(studentId);
		Map<String, Object> m = new HashMap<>();
		m.put(MyContent.CODE, BusinessEnum.SUCCESS.getCode());
		m.put(MyContent.MSG, BusinessEnum.SUCCESS.getDesc());
		return m;
	}
	
	//修改
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(@RequestBody ExamStudentBasicInfo examStudentBasicInfo){
		ssbkaoshi.updateByPrimaryKeySelective(examStudentBasicInfo);
		Map<String, Object> m = new HashMap<>();
		m.put(MyContent.CODE, BusinessEnum.SUCCESS.getCode());
		m.put(MyContent.MSG, BusinessEnum.SUCCESS.getDesc());
		return m;
	}
	
	//bzt查询
	@RequestMapping("/bzt")
	@ResponseBody
	public Map<String, Object> bzt(@RequestBody ExamStudentBasicInfo examStudentBasicInfo){
		Map<String, Object> m = new HashMap<>();
		List<ExamStudentBasicInfo> list = ssbkaoshi.listData2(examStudentBasicInfo);
		m.put(MyContent.CODE, BusinessEnum.SUCCESS.getCode());
		m.put(MyContent.MSG, BusinessEnum.SUCCESS.getDesc());
		m.put(MyContent.DATA, list);
		return m;
		
	}
}
